//
//  AccountUtil.m
//  BelApp
//
//  Created by Leon on 15/3/24.
//  Copyright (c) 2015年 苏州中资联. All rights reserved.
//

#import "LoginInfoUtil.h"
#import "LoginInfo.h"


#define LoginInfoFile [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"loginInfo.data"]

@implementation LoginInfoUtil

+ (void)saveAccount:(LoginInfo *)account
{
    [NSKeyedArchiver archiveRootObject:account toFile:LoginInfoFile];
}

+ (LoginInfo *)loginInfo
{
    // 取出账号
    LoginInfo *loginInfo = [NSKeyedUnarchiver unarchiveObjectWithFile:LoginInfoFile];
    
    return loginInfo;
}

+ (BOOL)clearLoginInfo
{
    NSFileManager *defaultManager = [NSFileManager defaultManager];
    if ([defaultManager isDeletableFileAtPath:LoginInfoFile]) {
        return [defaultManager removeItemAtPath:LoginInfoFile error:nil];
    }
    return false;
}

@end